package com.xcf.controller.base;


/**
 * @author WongBin
 * @date 2017/11/27.
 */
public class CommonResponse {
    private String code;
    private String desc;
    private Object data;

    public boolean isOk(){
        return "000000".equals(code);
    }
    public void initSuccess(){
        this.setCode("000000");
        setDesc("操作成功");
    }
    public static CommonResponse success(){
        CommonResponse ret = new CommonResponse();
        ret.initSuccess();
        return ret;
    }
    public static CommonResponse success(Object data){
        CommonResponse ret = new CommonResponse();
        ret.initSuccess();
        ret.setData(data);
        return ret;
    }

    public static CommonResponse success(String code,String desc,Object data){
        CommonResponse ret = new CommonResponse();
        ret.setCode(code);
        ret.setDesc(desc);
        ret.setData(data);
        return ret;
    }
    public static CommonResponse fail(String code,String desc){
        CommonResponse ret = new CommonResponse();
        ret.initSysError(code,desc);
        return ret;
    }
    public static CommonResponse fail(String desc){
        CommonResponse ret = new CommonResponse();
        ret.initSysError(desc);
        return ret;
    }
    public static CommonResponse fail(){
        CommonResponse ret = new CommonResponse();
        ret.initSysError();
        return ret;
    }

    public void initSysError(){
        setCode("009999");
        setDesc("系统错误");
    }
    public void initSysError(String msg){
        setCode("000999");
        setDesc(msg);
    }
    public void initSysError(String code,String msg){
        setCode(code);
        setDesc(msg);
    }

    @Override
    public String toString() {
        return "CommonResponse{" +
                "code='" + code + '\'' +
                ", desc='" + desc + '\'' +
                ", data=" + data +
                '}';
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
